@include('admin.header')
    <div class="x-body">
        <form class="layui-form" action="" method="post">
          <input type="hidden" value="{{$user->user_id}}" name="user_id"/>
          <div class="layui-form-item">
              <label for="goods_price" class="layui-form-label">
                  <span class="x-red">*</span>新密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="goods_price" name="user_pwd" required lay-verify="required"
                  autocomplete="off" class="layui-input input1">
              </div>
          </div>
            <div class="layui-form-item">
                <label for="goods_price" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="goods_price" name="user_pwd2" required lay-verify="required"
                           autocomplete="off" class="layui-input input2">
                </div>
            </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn btn" lay-filter="add" lay-submit="">
                  确定修改
              </button>
          </div>
      </form>
    </div>
    <div class="alert">
        提示信息
    </div>
    <style>
        .alert{
            position: fixed;
            width: 280px;
            height: 50px;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            z-index: 9999;
            color: #fff;
            text-align: center;
            line-height: 50px;
            font-size: 16px;
            display: none;
        }
    </style>
    <script>


        // var input1 = $('.input1'),
        //     input2 = $('.input2'),
        //     btn = $('.btn');
        //
        // $(".input2").blur(function(){
        //     if(input1.val() != input2.val()){
        //         $(".alert").html("密码不一致！").css({"background-color":"#41b314bb","border-color":"#3ca512bb"}).stop().fadeIn(500);
        //         setTimeout(function () {
        //             $(".alert").fadeOut(500);
        //         },2000)
        //     }
        // });
        // $(".btn").click(function(){
        //     if(input1.val() != input2.val()){
        //         $(".alert").html("密码不一致！").css({"background-color":"#41b314bb","border-color":"#3ca512bb"}).stop().fadeIn(500);
        //         setTimeout(function () {
        //             $(".alert").fadeOut(500);
        //         },2000)
        //     }
        // });

    </script>
    <script>
        //重置分页的样式
        function resetpage(){
            //把span标签改成a标签
            var spans = parent.$('.page-item span');
            for (let i = 0; i < spans.length; i++) {
                spans[i].outerHTML="<a href=''>"+spans[i].innerHTML+"</a>";
            }
            var arr = parent.$(".page-item a");
            for (let i = 0; i < arr.length; i++) {
                if (arr[i].innerHTML=="‹") {
                    arr[i].className = "prev";
                }else if(arr[i].innerHTML=="›"){
                    arr[i].className = "next";
                }
            }
            //将当前页设置为active
            parent.$(".active a").attr("class","num active");
            //把li 上面的active 去除
            parent.$("li.active").removeClass("active");
            //给页码a标签换类名
            parent.$(".page-item .page-link").attr("class","num");
        }
        //更新父级窗口的数据
        function getGoodData(page){
            $.ajax({
                type:"get",
                url:"{{url('/admin/toget_user_list')}}",
                data:"page="+page,
                dataType:"html",
                success:function(res){
                    parent.$(".list").html(res);
                    resetpage();

                }
            })
        }
        //请求接口获取所有数据的条数
        function getCount(){
            $.ajax({
                type:"get",
                url:"{{url('/admin/toget_user_count')}}",
                data:"",
                dataType:"text",
                success:function(res){
                    parent.$(".count").html("共有会员："+res+" 人");
                }
            })
        }

        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#addtime' //指定元素
            });

        });

        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
                ,layer = layui.layer

            //监听提交
            form.on('submit(add)', function(data){

                //data.field.good_dec = layedit.getContent(index);




                console.log(data.field);
                //console.log(data.field.user_pwd);
                if(data.field.user_pwd != data.field.user_pwd2) {
                    $(".alert").html("密码不一致！").css({"background-color":"#41b314bb","border-color":"#3ca512bb"}).stop().fadeIn(500);
                    setTimeout(function () {
                        $(".alert").fadeOut(500);
                    },2000)
                }else{
                    $.ajax({
                        url:"/admin/todo_user_editpwd",
                        type:"post",
                        data: data.field,
                        dataType:"json",
                        success: function(res) {
                            console.log(res);
                            if(res.code==1){
                                getGoodData(1);
                                getCount();
                                layer.alert(res.msg,function () {
                                    // 获得frame索引
                                    var index = parent.layer.getFrameIndex(window.name);
                                    //关闭当前frame
                                    parent.layer.close(index);
                                });
                            }else{
                                layer.alert(res.msg);
                            }
                        },
                        error:function(data) {
                            $(".alert").html("服务器错误！").css({"background-color":"#41b314bb","border-color":"#3ca512bb"}).stop().fadeIn(500);
                            setTimeout(function () {
                                $(".alert").fadeOut(500);
                            },2000)
                        }
                    });
                }
                //发异步，把数据提交给php

                return false;
            });
        });
    </script>
  </body>

</html>